package com.blb.community_admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.community_admin.entity.vo.ComplaintSuggestVO;
import com.blb.community_admin.service.IZyComplaintSuggestService;
import com.blb.community_admin.util.ResponseResult;
import com.blb.community_admin.util.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Api(tags = "投诉建议")
@RestController
public class ZyComplaintSuggestController {
    @Autowired
    private IZyComplaintSuggestService suggestService;

    @ApiOperation("查询全部")
    @GetMapping("/suggests")
    public List<ComplaintSuggestVO> getAllSuggest(){
        return suggestService.selectAllSuggest();
    }

    @ApiOperation("分页查询")
    @GetMapping("/suggests/page")
    public ResponseEntity<IPage<ComplaintSuggestVO>> getSuggestPage(ComplaintSuggestVO complaintSuggestVO){
        return ResponseEntity.ok(suggestService.getSuggestPage(complaintSuggestVO.getCurrent(),complaintSuggestVO.getSize(),complaintSuggestVO));
    }

    @ApiOperation("添加")
    @PostMapping("/suggest")
    public ResponseResult<String> addRepair(ComplaintSuggestVO complaintSuggestVO){
        complaintSuggestVO.setComplaintSuggestId(UUIDUtils.getId());
        complaintSuggestVO.setUserId(complaintSuggestVO.getOwnerId());
        suggestService.addSuggest(complaintSuggestVO);

        return  ResponseResult.ok("添加成功");
    }

    @ApiOperation("更新")
    @PutMapping("/suggest")
    public ResponseResult<String> updateRepair(@RequestBody ComplaintSuggestVO complaintSuggestVO){
        suggestService.updateById(complaintSuggestVO);
        return ResponseResult.ok("更新成功");
    }
    @ApiOperation("删除")
    @DeleteMapping("/suggest/{complaintSuggestId}")
    public ResponseResult<String> deleteRepair(@PathVariable Long complaintSuggestId){
        suggestService.removeById(complaintSuggestId);
        return ResponseResult.ok("删除成功");
    }
    @ApiOperation("导出Excel")
    @GetMapping("/suggest/download")
    public ResponseEntity<String> downloadExcel(HttpServletResponse response) throws IOException {
        suggestService.downloadExcel(response);
        return ResponseEntity.ok("下载成功");
    }
}

